<script>
  export default {
    data() {
      return {
        user_id:'',  //存放当前用户id
        searchText:null, //存放商品名称内容
        searchDate:null, //存放日期搜索框的内容
        products: [], //存储商品浏览记录信息
      };
    },
    created() {
      this.user_id = localStorage.getItem('user_id');
    },
  methods: {
    LoadBrowseInfo(){
      this.$http.get("http://localhost:8080/browse/querybytwo",{params:{
        user_id:this.user_id,
        name:this.searchText,
        date:this.searchDate
        }}).then((res)=>{
        this.products=res.data
        console.log(this.products);
      }).catch(function(err){
    console.log(err);
  })
  },
    searchProducts() {
      console.log(this.products);
      this.LoadBrowseInfo();
    }
  },
  mounted(){
      this.LoadBrowseInfo();
  }
}
</script>

<template>
<el-card>
  <template #header>
    <div class="card-header" style="text-align: center;">
    <span>
      <h2 class="card-title" style="margin: 0; color: #79bbff; font-size: 24px; font-weight: bold; animation: fadeIn 2s ease-in-out;">我的浏览记录</h2>
    </span>
    </div>
  </template>
   <div class="search-box-right">
     <el-date-picker
         v-model="searchDate"
         type="date"
         placeholder="--请选择日期--"
         format="YYYY-MM-DD"
         value-format="YYYY-MM-DD"
     />
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <el-input
          v-model="searchText"
          style="width:200px"
          size="default"
          placeholder="请输入商品名称"
          clearable
      />
      &nbsp&nbsp
      <el-button type="primary" round @click="searchProducts">搜索</el-button>
    </div>
  <el-divider border-style="dashed" />

<!-- 展示浏览过的商品信息 -->
      <div class="product-list">
        <div v-for="goods in products" :key="goods.goods_id" class="product-item">
          <router-link :to="{name:'GoodsDetails',params:{goodsId:goods.goods_id,categoryId:goods.category_id} }">
              <img :src="'http://localhost:8080/image/upload/'+goods.goods_image" alt="商品图片" style="width: 200px; height:200px;"/>
          </router-link>
              <div class="product-info">
                {{ goods.goods_name }}&nbsp;￥{{ goods.goods_price }}
                <br/>
                {{goods.browse_time}}
              </div>
            </div>
      </div>
</el-card>
  </template>


  <style scoped>
    .search-box-right {
      margin-top: 50px;
      margin-bottom: 50px;
      text-align: center;
    }
  .product-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 100px;
  }

  .product-item {
    border: 1px solid #ddd;
    padding: 10px;
    width: 200px;
  }
  .product-info {
    margin-top: 10px;
  }
  </style>
